package org.dawnsql.stock.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;

@Controller
public class MyDownDataController {

    @CrossOrigin(origins = "https://xueqiu.com", maxAge = 3600)
    @RequestMapping(value = "/run_sql")
    public @ResponseBody
    String run_sql(ModelMap model, HttpServletRequest request,
                   HttpServletResponse response,
                   @RequestParam(value = "code", required = false) String code) throws UnsupportedEncodingException {

        String jsonpCallback = request.getParameter("callback");
        if (code != null) {
            System.out.println(code);
            return jsonpCallback + "({data:'true'})";
        }
        return jsonpCallback + "({data:'false'})";
    }

//    @RequestMapping(value = "/postwin")
//    public String postWin(ModelMap model, HttpServletRequest request,
//                   HttpServletResponse response) throws UnsupportedEncodingException {
//
//        System.out.println(request);
//        return "postwin";
//    }

    @RequestMapping(value = "/login")
    public String login(ModelMap model, HttpServletRequest request,
                        HttpServletResponse response,
                        @RequestParam(value = "err", required = false) String err)
    {
        return "login";
    }
}



































































































